package com.hzecool.core.activity.webview;

import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.webkit.WebView;

import com.github.lzyzsd.jsbridge.BridgeWebView;
import com.github.lzyzsd.jsbridge.BridgeWebViewClient;

/**
 * Discribe:WebViewClient
 * 用来设置给WebView 在应用内打开网页
 * Created by tutu on 2017/3/29.
 */

public class TWebViewClient extends BridgeWebViewClient {

    public TWebViewClient(BridgeWebView webView) {
        super(webView);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        Uri uri = null;
        try {
            uri = Uri.parse(url);

            if (uri != null && TextUtils.equals(uri.getScheme(), "taobao")) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.addCategory(Intent.CATEGORY_BROWSABLE);
                intent.setData(uri);
                if (view.getContext() != null) {
                    view.getContext().startActivity(intent);
                }
                return true;
            }
        } catch (Exception e) {
        }
        return super.shouldOverrideUrlLoading(view, url);

    }
}
